/**
 * Copyright (c) 2006-2009 by Shanghai UnuTrip Network Technology Development Co.,Ltd
 * All rights reserved.
 */


package com.unusap.remote.core.remote.factory;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.ReflectionUtils;

/**
 * 
 * @author danson
 * FactoryBeanWebServiceDirector.java
 * 2009-9-4
 */
public class FactoryBeanWebServiceDirector<T extends FactoryBean & InitializingBean> {
	
	private T factoryBean;

	public FactoryBeanWebServiceDirector(T factoryBean) {
		try {
			this.factoryBean = factoryBean;
			this.factoryBean.afterPropertiesSet();
		} catch (Exception e) {
			ReflectionUtils.rethrowRuntimeException(e);
		}
	}
	
	@SuppressWarnings("unchecked")
	public <WebService> WebService getWebService() {
		try {
			return (WebService) factoryBean.getObject();
		} catch (Exception e) {
			ReflectionUtils.rethrowRuntimeException(e);
			return null;
		}
	}

}
